<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>企业注册</title>
    <link rel="stylesheet" href="../lib/bootstrap-3.3.5-dist/css/bootstrap.min.css">
    <script src="../lib/bootstrap-3.3.5-dist/js/jquery-1.11.3.js"></script>
    <script src="../lib/bootstrap-3.3.5-dist/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="../css/business-register.css">
</head>

<body>
    <div id="back">
        <div class="container">
            <div class="row">
                <div class="col-md-3"></div>
                <div class="col-md-6">
                    <div id="logo"></div>

                    <form action="" onsubmit="return checkFrom()">
                        <h3>企业账号注册</h3>
                        <div class="green"></div>
                        <br>
                        <span id="company_hint"></span>
                        <input type="text" onblur="companyCheck()" placeholder="请输入企业名称，需与营业执照一致" id="company">
                        <br>
                        <span id="name_hint"></span>
                        <input type="text" placeholder="请输入负责人姓名" onchange="nameCheck()" id="name">
                        <br>
                        <input type="text" onblur="phone_hint()" onkeyup="phoneCheck()" placeholder="请输入手机号码"
                            name="username" id="username">
                        <span id="phone_hint"></span>

                        <button id="ma" type="button">验证码</button>
                        <br>
                        <span id="code_hint"></span>
                        <input type="text" onblur="codeCheck()" placeholder="请输入验证码" id="code">
                        <!-- 验证码显示在这个div里面 -->
                        <div id="checkcode" class="code"></div>
                        <br>
                        <span id="pass_hint"></span>
                        <input type="password" onblur="pass_hint()" onkeyup="passCheck()" placeholder="请输入密码"
                            name="password" id="password">
                        <br>
                        <span id="email_hint"></span>
                        <input type="text" onblur="email_hint()" onkeyup="emailCheck()" name="email" id="email"
                            placeholder="请输入联系邮箱">
                        <br>
                        <button id="register" type="submit">注册</button>
                        <div>
                            <input type="checkbox" id="checkbox">
                            <span class="grey">勾选确认你已经同意<span class="gre">优领人才的平台协议</span></span>
                        </div>

                    </form>
                </div>
                <div class="col-md-3"></div>
            </div>
        </div>
    </div>

</body>

</html>
<script>
    //企业名称验证   非空
    function companyCheck() {
        let check = false;
        let company = $('#company').val();
        let company_hint = document.getElementById('#company_hint')
        if (company.length <= 0) {
            console.log(company)
            console.log(123)
            company_hint.innerHTML = '企业名称不能为空';
            check=false;
        }
        return check;

    }

    //负责人姓名验证
    function nameCheck() {
        let check = false;
        let name = document.getElementById('#name').value;
        let name_hint = document.getElementById('#name_hint')
        if (name.length < 0) {
            console.log(123)
            name_hint.innerHTML = '企业名称不能为空';
            check =false;
        }
        return check;
    }

    function checkMobile(strMobile) {
        var regu = /^1[3456789]\d{9}$/;
        if (regu.test(strMobile)) {
            return true;
        }
        else {
            return false;
        }
    }

    function phoneCheck() {
        let check = false;
        let phone = $('#username').val();
        let phone_hint = document.getElementById('phone_hint');
        let flag = checkMobile(phone)
        if (flag) {
            phone_hint.innerHTML = "√";
            check= true;
        } else {
            phone_hint.innerHTML = "❌";
            check= false;
        }
        return check;
    }


    //密码验证
    function passCheck() {
        let check = false;
        let pass = $('#password').val();
        let pass_hint = document.getElementById('pass_hint');
        if (pass.length < 6) {
            pass_hint.innerHTML = "密码太短";
            check= false;
        } else {
            pass_hint.innerHTML = "密码格式合格";
            check= true;
        }

    }


    //邮箱验证
    function checkEmail(strEmail) {
        let check=false;
        var emailReg = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/;
        if (emailReg.test(strEmail)) {
            check= true;
        }
        else {
            check= false;
        }
        return check;
    };

    function emailCheck() {
        let check = false;
        let email = $('#email').val();
        let email_hint = document.getElementById('email_hint');
        let flag = checkEmail(email)
        if (flag) {
            email_hint.innerHTML = "邮箱格式正确";
            check=false;
        } else {
            email_hint.innerHTML = "邮箱格式错误";
            check= true;
        }
        return check;

    }



    var code = '';
    $('#ma').click(() => {
        let codeArr = new Array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
        for (let i = 0; i < 4; i++) {
            let charNum = Math.floor(Math.random() * 10)
            code += codeArr[charNum];
        }
        $('#checkcode').css({ display: 'block' })
        $('#checkcode').html(code);
    })

    //检验验证码是否正确 
    function codeCheck() {
        let check = false;
        //获取输入的验证码
        let inputcode = $('#code').val()
        let code_hint = document.getElementById('code_hint');
        console.log(code)
        if (inputcode != code) {
            code_hint.innerHTML = "验证码错误";
            check= false;
        } else {
            code_hint.innerHTML = "验证码正确";
            check= true;
        }
        return check;
    }

    function checkFrom() {
        let check = companyCheck() && nameCheck() && phoneCheck() && passCheck() && codeCheck() && emailCheck();
        return check;
    }


    $('#register').click(function () {




        // $.ajax({
        //     url: '/register',
        //     method: 'post',
        //     data: {
        //         username: $('input[name=username]').val(),
        //         password: $('input[name=password]').val()
        //     },
        //     success: (res) => {
        //         alert(res);
        //         location.href='./login.html'
        //     }
        // })
        // console.log(123);
        // alert('注册成功!')
        // location.href = './login.html'

        // let Inputcode = $('#code').val()
        // console.log(Inputcode)
    })



</script>